package com.javatest;

/**
 * @author LL
 * 对于一个有正有负的整数数组，请找出总和最大的连续数列。给定一个int数组A和数组大小n，
 * 请返回最大的连续数列的和。保证n的大小小于等于3000。
 * @create 2020-12-11 14:02
 */
public class Subject19 {

    public static int getMaxSum(int[] A, int n) {
        int sum = -99999,s;
        for (int i = 0; i < n; i++) {
            s = 0;
            for (int j = i; j < n; j++) {
                s += A[j];
                if (s > sum)
                    sum = s;
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        int[] its = {1,2,3,6,1,100};
        int maxSum = getMaxSum(its, 6);
        System.out.println(maxSum);
    }
}
